<template xmlns='http://www.w3.org/1999/html'>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('课程表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多<a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="showModal(record.courseId)">查看章节</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <div>
      <!--弹框-->
      <a-modal v-model="visible" title="博添实训" @ok="handleOk" width='800px' >
        <div>
          <a-button type="primary" @click="showModal2">
            新增章节
          </a-button>
          <a-modal okText='添加' v-model="visible2" title="博添实训" @ok="onSubmit()">
            <a-radio-group name="radioGroup" :default-value="1" @change="onChange">
              <a-radio :value="1">
                添加章
              </a-radio>
              <a-radio :value="2">
                添加节
              </a-radio>
            </a-radio-group>
              <!--添加表单-->
              <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-form-model-item label="章名称" v-if='sectionRedio==1'>
                  <a-input v-model="form.sectionName" placeholder="请输入该章名称" />
                </a-form-model-item>
                  <a-form-model-item label="节名称" v-if='sectionRedio==2'>
                    <a-input v-model="form.sectionName" placeholder="请输入该节名称" />
                  </a-form-model-item>
                    <a-form-model-item label="本章简介" v-if='sectionRedio==1'>
                      <a-input v-model="form.sectionAbout" placeholder="请输入该章简介" />
                    </a-form-model-item>
                  <a-form-model-item label="本节简介" v-if='sectionRedio==2'>
                     <a-input v-model="form.sectionAbout" placeholder="请输入该节简介" />
                  </a-form-model-item>
                <a-form-model-item label="所属课程" v-if='sectionRedio==1'>
                  <a-select v-model="form.courseId" placeholder="本章所属课程">
                    <a-select-option v-for='(abcde,key3) in selectCourseList' :value=abcde.courseId :key='key3'>
                      {{abcde.courseName}}
                    </a-select-option>
                  </a-select>

                </a-form-model-item>
                <a-form-model-item label="所属章" v-if='sectionRedio==2'>
                  <a-select v-model="form.sectionId" placeholder="本节所属章">
                    <a-select-option v-for='(abcdef,key2) in zhangList' :key='key2' >
                      {{abcdef.sectionName}}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="视频地址" v-if='sectionRedio==2'>
                  <a-input v-model="form.address" placeholder="请输入本节的视频所在网址" />
                </a-form-model-item>
                <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
<!--                  <a-button type="primary" @click="onSubmit(from)">-->
<!--                    11111增加-->
<!--                  </a-button>-->
<!--                  <a-button style="margin-left: 10px;">-->
<!--                   取消增加-->
<!--                  </a-button>-->
                </a-form-model-item>
              </a-form-model>
          </a-modal>
        </div>
        <div>
            <!--课程的章节显示-->
          <a-collapse accordion>
            <a-collapse-panel :header="item.sectionName" v-for='(item,key) in courseList' :key='key'>
              <span v-for='(cItem,cKey) in item.sectionList' :key='cKey'>
                {{cItem.sectionName}}<br>
              </span>
            </a-collapse-panel>
          </a-collapse>
        </div>
      </a-modal>
    </div>
    <course-modal ref="modalForm" @ok="modalFormOk"></course-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CourseModal from './modules/CourseModal'
  import { defineComponent, ref } from 'vue';
  import { getAction, httpAction, postAction } from '../../../api/manage'
  export default {
      name: 'CourseList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CourseModal

    },
    data () {
      return {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
        form:{
          name: '',
          region: undefined,
          date1: undefined,
          delivery: false,
          type: [],
          resource: '',
          desc: '',
          courseId:"",
          courseName:""
        },
        sectionRedio:1,
        visible: false,
        visible2: false,
        description: '课程表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'课程编号',
            align:"center",
            dataIndex: 'courseId'
          },
          {
            title:'课程名称',
            align:"center",
            dataIndex: 'courseName'
          },
          {
            title:'课程时长',
            align:"center",
            dataIndex: 'courseMin'
          },
          {
            title:'课程价格',
            align:"center",
            dataIndex: 'courseMoney'
          },
          {
            title:'课程简介',
            align:"center",
            dataIndex: 'courseAbout'
          },
          {
            title:'专业分类编号',
            align:"center",
            dataIndex: 'majorTypeId',
            customRender: (text) => {
              for (let i = 0; i <this.getAllmajorTypeList.length; i++) {
                if(text==this.getAllmajorTypeList[i].majorTypeId){
                  return this.getAllmajorTypeList[i].majorTypeName;
                }
              }
            }
          },
          {
            title:'课程标题',
            align:"center",
            dataIndex: 'courseTitle'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/course/course/list",
          delete: "/course/course/delete",
          deleteBatch: "/course/course/deleteBatch",
          exportXlsUrl: "/course/course/exportXls",
          importExcelUrl: "course/course/importExcel",
          //查询全部课程
          checkCourseSectionUrl:"/course/course/getcousesection",
          getCourseSectionUrl:"/course/course/getCourseSection",
          courseSectionFromUrl:"/cousesection/courseSection/add",
          //查看全部章节
          sectionListUrl:"/cousesection/courseSection/getCourseSectionList",
          //查询全部类型的
          getmajorTypeUrl:"/majortype/majorType/getmajorType"

        },
        dictOptions:{},
        superFieldList:[],
        section:[],
        /*testList:[{name:1,age:21,cList:[{cName:2,cAge:22},{cName:2,cAge:22},{cName:2,cAge:22}]},{name:1,age:21,cList:[{cName:2,cAge:22}]},{name:1,age:21,cList:[{cName:2,cAge:22},{cName:2,cAge:22}]}]*/
        courseList:[],
        //课程下拉框的集合
        selectCourseList:[],
        sectionList:[],
        //章的下拉框
        zhangList:[],
        //查询全部类型的
        getAllmajorTypeList:[],

      }
    },
    created() {
      this.getmajorTypeList();
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      getmajorTypeList(){
        getAction(this.url.getmajorTypeUrl,{}).then((res)=>{
          if (res.success){
            debugger
            this.getAllmajorTypeList=res.result
          }
        })
      },
      onChange(e) {
        if ( e.target.value==1){
          this.sectionRedio=1
        }
        if ( e.target.value==2){
          this.sectionRedio=2
        }
      },
      onSubmit() {
        postAction(this.url.courseSectionFromUrl,this.form).then((res)=>{
          if(res.success){
            this.$message.success('添加成功');
          }else {
            this.$message.warning('添加失败');
          }
          this.visible2 = false;
        })
      },
      showModal2() {
        this.visible2 = true;
      },
      // handleOk2(e) {
      //   this.visible2 = false;
      // },

      /*查看章节弹窗*/
      showModal(courseId) {

        this.visible = true;
        this.form.courseId=courseId;
        getAction(this.url.checkCourseSectionUrl+"?courseId="+courseId).then((res)=>{
          if(res.success){
            this.courseList=res.result
          }
        })
      },
      handleOk(e) {
        this.visible = false;

      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'courseId',text:'课程编号',dictCode:''})
        fieldList.push({type:'string',value:'courseName',text:'课程名称',dictCode:''})
        fieldList.push({type:'string',value:'courseMin',text:'课程时长',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'courseMoney',text:'课程价格',dictCode:''})
        fieldList.push({type:'string',value:'courseAbout',text:'课程简介',dictCode:''})
        fieldList.push({type:'string',value:'majorTypeId',text:'专业分类编号',dictCode:''})
        fieldList.push({type:'string',value:'courseTypeId',text:'课程分类编号',dictCode:''})
        this.superFieldList = fieldList
      }
    },
    mounted() {
        getAction(this.url.getCourseSectionUrl).then((res) => {
          //获取课程的下拉框
          if (res.success) {
            this.selectCourseList = res.result
          }
        }),
          //获取章的下拉框
          getAction(this.url.sectionListUrl).then((res)=>{
            if (res.success){
              this.zhangList=res.result
            }
          })
    },
    initDictConfig(){
      },
    }

</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>